package com.example.androidlearning2200;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashSet;
import java.util.Set;

public class Wdg2Activity extends BaseActivity {

    Set<String> hobbySet = new HashSet<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wdg2);
        RadioGroup rgSex = findViewById(R.id.rgSex);
        CheckBox cbFootball = findViewById(R.id.cbFootball);
        CheckBox cbBasketball = findViewById(R.id.cbBasketball);
        CheckBox cbPingpang = findViewById(R.id.cbPingpang);
        CheckBox cbVolleyball = findViewById(R.id.cbVolleyball);
        ProgressBar pbTerm = findViewById(R.id.pbTerm);
        TextView tvTerm = findViewById(R.id.tvTerm);
        SeekBar sbTerm = findViewById(R.id.sbTerm);
        TextView tvAge = findViewById(R.id.tvAge);
        Switch ss = findViewById(R.id.ss);

        rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.rbFemale:
                        showToast("女");
                        break;
                    case R.id.rbMale:
                        showToast("男");
                        break;
                }
            }
        });
        cbFootball.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                hobbySet.add("足球");
            } else {
                hobbySet.remove("足球");
            }
            showToast(hobbySet.toString());
        });
        cbBasketball.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                hobbySet.add("篮球");
            } else {
                hobbySet.remove("篮球");
            }
            showToast(hobbySet.toString());
        });
        cbPingpang.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                hobbySet.add("乒乓球");
            } else {
                hobbySet.remove("乒乓球");
            }
            showToast(hobbySet.toString());
        });
        cbVolleyball.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                hobbySet.add("排球");
            } else {
                hobbySet.remove("排球");
            }
            showToast(hobbySet.toString());
        });
        // 修改进度的方法
        pbTerm.setProgress(4);
        tvTerm.setText("4/6");

        sbTerm.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                // 进度变化后触发
                tvAge.setText(i + "");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // 开始拖动时触发
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // 拖动结束时触发
            }
        });

        ss.setOnCheckedChangeListener((compoundButton, b) -> showToast("蓝牙是否开启：" + (b ? "开启" : "关闭")));
    }

    private void showToast(String tipMsg) {
        Toast.makeText(Wdg2Activity.this, tipMsg, Toast.LENGTH_SHORT).show();
    }
}